| Conditions | 1 |
| Paths | 1 |
| Total Lines | 144 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var assert = require('chai').assert, |
||
| 4 | describe('Person', function(){ |
||
| 5 | |||
| 6 | it('Create plain', function(){ |
||
| 7 | var newPerson = new GedcomX.Person(), |
||
| 8 | person = GedcomX.Person(); |
||
| 9 | assert.instanceOf(newPerson, GedcomX.Person, 'An instance of Person is not returned when calling the constructor with new.'); |
||
| 10 | assert.instanceOf(person, GedcomX.Person, 'An instance of Person is not returned when calling the constructor without new.'); |
||
| 11 | }); |
||
| 12 | |||
| 13 | it('Create with JSON', function(){ |
||
| 14 | var person = GedcomX.Person({ |
||
| 15 | id: 'testPerson', |
||
| 16 | private: true, |
||
| 17 | gender: { |
||
| 18 | type: 'http://gedcomx.org/Female' |
||
| 19 | }, |
||
| 20 | names: [ |
||
| 21 | { |
||
| 22 | type: 'http://gedcomx.org/BirthName', |
||
| 23 | nameForms: [ |
||
| 24 | { |
||
| 25 | fullText: 'Joanna Hopkins' |
||
| 26 | } |
||
| 27 | ] |
||
| 28 | } |
||
| 29 | ], |
||
| 30 | facts: [ |
||
| 31 | { |
||
| 32 | type: 'http://gedcomx.org/Birth', |
||
| 33 | date: { |
||
| 34 | formal: '+2001-04-09' |
||
| 35 | }, |
||
| 36 | place: { |
||
| 37 | original: 'Farm house' |
||
| 38 | } |
||
| 39 | } |
||
| 40 | ] |
||
| 41 | }); |
||
| 42 | assert.equal(person.getId(), 'testPerson'); |
||
| 43 | assert.equal(person.isPrivate(), true); |
||
| 44 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
||
| 45 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
||
| 46 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
||
| 47 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
||
| 48 | }); |
||
| 49 | |||
| 50 | it('Create with mixed data', function(){ |
||
| 51 | var person = GedcomX.Person({ |
||
| 52 | id: 'testPerson', |
||
| 53 | private: true, |
||
| 54 | gender: GedcomX.Gender({ |
||
| 55 | type: 'http://gedcomx.org/Female' |
||
| 56 | }), |
||
| 57 | names: [ |
||
| 58 | GedcomX.Name({ |
||
| 59 | type: 'http://gedcomx.org/BirthName', |
||
| 60 | nameForms: [ |
||
| 61 | { |
||
| 62 | fullText: 'Joanna Hopkins' |
||
| 63 | } |
||
| 64 | ] |
||
| 65 | }) |
||
| 66 | ], |
||
| 67 | facts: [ |
||
| 68 | GedcomX.Fact({ |
||
| 69 | type: 'http://gedcomx.org/Birth', |
||
| 70 | date: GedcomX.Date({ |
||
| 71 | formal: '+2001-04-09' |
||
| 72 | }), |
||
| 73 | place: GedcomX.PlaceReference({ |
||
| 74 | original: 'Farm house' |
||
| 75 | }) |
||
| 76 | }) |
||
| 77 | ] |
||
| 78 | }); |
||
| 79 | assert.equal(person.getId(), 'testPerson'); |
||
| 80 | assert.equal(person.isPrivate(), true); |
||
| 81 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
||
| 82 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
||
| 83 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
||
| 84 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
||
| 85 | }); |
||
| 86 | |||
| 87 | it('Build', function(){ |
||
| 88 | var person = GedcomX.Person() |
||
| 89 | .setId('testPerson') |
||
| 90 | .setPrivate(true) |
||
| 91 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
||
| 92 | .addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
||
| 93 | .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))); |
||
| 94 | assert.equal(person.getId(), 'testPerson'); |
||
| 95 | assert.equal(person.isPrivate(), true); |
||
| 96 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
||
| 97 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
||
| 98 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
||
| 99 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
||
| 100 | }); |
||
| 101 | |||
| 102 | it('toJSON', function(){ |
||
| 103 | var data = { |
||
| 104 | id: 'testPerson', |
||
| 105 | private: true, |
||
| 106 | gender: { |
||
| 107 | type: 'http://gedcomx.org/Female' |
||
| 108 | }, |
||
| 109 | names: [ |
||
| 110 | { |
||
| 111 | type: 'http://gedcomx.org/BirthName', |
||
| 112 | nameForms: [ |
||
| 113 | { |
||
| 114 | fullText: 'Joanna Hopkins' |
||
| 115 | } |
||
| 116 | ] |
||
| 117 | } |
||
| 118 | ], |
||
| 119 | facts: [ |
||
| 120 | { |
||
| 121 | type: 'http://gedcomx.org/Birth', |
||
| 122 | date: { |
||
| 123 | formal: '+2001-04-09' |
||
| 124 | }, |
||
| 125 | place: { |
||
| 126 | original: 'Farm house' |
||
| 127 | } |
||
| 128 | } |
||
| 129 | ] |
||
| 130 | }, person = GedcomX.Person(data); |
||
| 131 | assert.deepEqual(person.toJSON(), data); |
||
| 132 | person = GedcomX.Person() |
||
| 133 | .setId('testPerson') |
||
| 134 | .setPrivate(true) |
||
| 135 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
||
| 136 | .addName(GedcomX.Name().setType('http://gedcomx.org/BirthName').addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
||
| 137 | .addFact(GedcomX.Fact().setType('http://gedcomx.org/Birth').setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))); |
||
| 138 | assert.deepEqual(person.toJSON(), data); |
||
| 139 | }); |
||
| 140 | |||
| 141 | it('constructor does not copy instances', function(){ |
||
| 142 | var obj1 = GedcomX.Person(); |
||
| 143 | var obj2 = GedcomX.Person(obj1); |
||
| 144 | assert.strictEqual(obj1, obj2); |
||
| 145 | }); |
||
| 146 | |||
| 147 | }); |